package world.hezi.scheduler;

import net.mamoe.mirai.contact.Contact;
import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import world.hezi.utils.PicturesUtil;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author wangzijian
 * @since 2023/12/4 10:18
 */
public class DiaoScheduler {
    public static void schedule(List<Contact> contactList){
        Timer timer = new Timer();
        File diaoDir = new File("D:\\haha");
        File[] files = diaoDir.listFiles();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    for (Contact contact : contactList) {
                        if (contact == null){
                            continue;
                        }
                            MessageChainBuilder messages = new MessageChainBuilder();
                        Image image = PicturesUtil.uploadAndGetImage(files[(int) (files.length* Math.random())], contact);
                        MessageChain build = messages
                                    .append("每日弔图")
                                .append(image)
                                .build();
                        contact.sendMessage(build);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        },1000*60*60,1000*60*60*4);
    }
}
